"""
输入必选项添加客户
"""
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest
#定位器
name_locator = (By.NAME, "name")
password_locator = (By.NAME, "password")
login_locator = (By.CSS_SELECTOR, "body > div.container > div > div.span4 > div > form > fieldset > input.btn.btn-primary")
kh_link_locator =(By.LINK_TEXT,"客户")
kh_xjkh_locator = (By.LINK_TEXT,"新建客户")
kh_tjkh_khmc_locator =(By.ID,"name")
kh_tjkh_xm_locator =(By.CSS_SELECTOR,"#form1 > table > tbody > tr:nth-child(8) > td:nth-child(2) > input")
kh_tjkh_sj_locator =(By.CSS_SELECTOR,"#form1 > table > tbody > tr:nth-child(10) > td:nth-child(4) > input")
kh_tjkh_bc_locator = (By.XPATH,'//*[@id="form1"]/table/tfoot/tr/td/input[1]')
#所需数据
name = "admin"
password = "123456"
khmc = "C4"
xm = "杨科长"
sj = "13345665401"
#操作
#打开浏览器
driver = webdriver.Chrome()
#最大化窗口
driver.maximize_window()
#进入悟空CRM登录界面
driver.get("http://192.168.1.25/crm/")
#输入用户名
driver.find_element(*name_locator).send_keys(name)
#输入密码
driver.find_element(*password_locator).send_keys(password)
#点击确定按钮
driver.find_element(*login_locator).click()
#点击线索按钮
driver.find_element(*kh_link_locator).click()
#点击新建客户
driver.find_element(*kh_xjkh_locator).click()
#输入客户名称
driver.find_element(*kh_tjkh_khmc_locator).send_keys(khmc)
#输入首要联系人姓名
driver.find_element(*kh_tjkh_xm_locator).send_keys(xm)
#输入首要联系人手机
driver.find_element(*kh_tjkh_sj_locator).send_keys(sj)
#页面向下滑动
js = "window.scrollTo(0,document.body.scrollHeight)"
driver.execute_script(js)
sleep(2)
#点击保存按钮
driver.find_element(*kh_tjkh_bc_locator).click()
sleep(2)
if __name__ == '__main__':
    unittest.main()